<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <body>

        <ui:composition template="./potentialCustomers.xhtml">

            <ui:define name="tabContent">
                <h:form>
                    <p:panel>
                        <table border="0" cellspacing="5">
                            <tbody>
                                <tr>
                                    <td style="vertical-align: top">
                                        <h:panelGrid columns="2">
                                            Đầu số* 
                                            <h:selectManyMenu value="#{tblRawMtBean.selectedShortCodes}" style="width: 150px; height: 200px;">
                                                <f:selectItems value="#{tblRawMtBean.shortCodeMap}"/>
                                            </h:selectManyMenu>

                                        </h:panelGrid>
                                    </td>

                                    <td style="vertical-align: top">
                                        <h:panelGrid columns="2">
                                            Mạng
                                            <h:selectManyMenu value="#{tblRawMtBean.selectedOperators}" style="width: 150px; height: 65px">
                                                <f:selectItem itemLabel="Viettel" itemValue="Viettel"/>
                                                <f:selectItem itemLabel="Mobifone" itemValue="Mobifone"/>
                                                <f:selectItem itemLabel="Vinaphone" itemValue="Vinaphone"/>
                                            </h:selectManyMenu>
                                            Miền
                                            <h:selectManyMenu value="#{tblRawMtBean.selectedRegions}" style="width: 150px; height: 65px">
                                                <f:selectItem itemLabel="Miền Bắc" itemValue="Miền Bắc"/>
                                                <f:selectItem itemLabel="Miền Trung" itemValue="Miền Trung"/>
                                                <f:selectItem itemLabel="Miền Nam" itemValue="Miền Nam"/>
                                            </h:selectManyMenu>
                                            Ngày bắt đầu*
                                            <p:calendar value="#{tblRawMtBean.startDate}" pattern="dd/MM/yyyy" timeZone="Asia/Saigon" navigator="true"
                                                        required="true" requiredMessage="Bạn chưa điền ngày bắt đầu"/>
                                            Ngày kết thúc*
                                            <p:calendar value="#{tblRawMtBean.endDate}" pattern="dd/MM/yyyy" timeZone="Asia/Saigon" navigator="true"
                                                        required="true" requiredMessage="Bạn chưa điền ngày kết thúc"/>
                                        </h:panelGrid>
                                    </td>

                                    <td style="vertical-align: top">
                                        <h:panelGrid columns="2">
                                            Nội dung MT
                                            <p:inputText value="#{tblRawMtBean.content}"/>
                                            Cú pháp MO
                                            <p:inputText value="#{tblRawMtBean.moSyntax}"/>
                                        </h:panelGrid>
                                    </td>
                                </tr>
                            </tbody>
                        </table>

                        <h:panelGrid columns="5">
                            <p:commandButton ajax="false" value="Tìm kiếm" rendered="#{!tblRawMtBean.edit}" action="#{tblRawMtBean.search()}"/>
                        </h:panelGrid>
                    </p:panel>
                </h:form>
                <br/>
                <h:form id="form">
                    <p:dataTable id="rawMtTable" value="#{tblRawMtBean.list}" var="item" paginator="false"
                                 selection="#{tblRawMtBean.selectedList}" selectionMode="multiple" resizableColumns="true" scrollable="true">

                        <f:facet name="header">  
                            <div align="left">
                                <p:commandButton update="rawMtTable" value="Cập nhật" image="ui-icon ui-icon-check" action="#{tblRawMtBean.updateAll()}"/>  
                            </div>
                        </f:facet>

                        <f:facet name="footer">  
                            <div align="left">
                                <p:commandButton update="rawMtTable" value="Cập nhật" image="ui-icon ui-icon-check" action="#{tblRawMtBean.updateAll()}"/>  
                            </div>
                        </f:facet>

                        <p:column headerText="ID" sortBy="#{item.id}" style="width: 30px">
                            #{item.id}
                        </p:column>
                        <p:column headerText="Đầu số" sortBy="#{item.sc}" style="width: 40px">
                            #{item.sc}
                        </p:column>
                        <p:column headerText="Ngày" style="width: 60px">
                            <h:outputText value="#{item.time}">
                                <f:convertDateTime pattern="dd/MM/yyyy" timeZone="Asia/Saigon"/>
                            </h:outputText>
                        </p:column>
                        <p:column headerText="Nội dung MT" sortBy="#{item.content}" style="width: 150px">
                            #{item.content}
                        </p:column>
                        <p:column headerText="Mã tỉnh" sortBy="#{item.gen2}" style="width: 70px">
                            <p:inputText value="#{item.gen2}" size="5"/>
                        </p:column>
                        <p:column headerText="Nội dung rút gọn" sortBy="#{item.gen1}" style="width: 100px">
                            <p:inputText value="#{item.gen1}" size="8"/>
                        </p:column>
                        <p:column headerText="Cú pháp MO" sortBy="#{item.gen3}" style="width: 100px">
                            <p:inputText value="#{item.gen3}" size="8"/>
                        </p:column>
                        <p:column headerText="Kết quả" sortBy="#{item.result}" style="width: 60px">
                            <h:selectOneRadio value="#{item.result}" layout="pageDirection" border="0">
                                <f:selectItem itemLabel="Ăn" itemValue="1"/>
                                <f:selectItem itemLabel="Xịt" itemValue="0"/>
                            </h:selectOneRadio>
                        </p:column>
                        <p:column headerText="DS"  style="width: 40px">
                            <p:commandLink value="#{item.count}" action="#{tblRawMoBean.search(item.gen3, item.time, item.sc)}" 
                                           update="form:mdnTable" onsuccess="mdnDialog.show();"/>
                        </p:column>
                        <p:column headerText="Xóa"  style="width: 40px">
                            <p:commandButton image="ui-icon ui-icon-close" action="#{tblRawMtBean.delete(item)}" 
                                             update="form"/>
                        </p:column>
                    </p:dataTable>

                    <p:dialog width="200" hideEffect="explode" widgetVar="mdnDialog" 
                              modal="true" header="Danh sách khách hàng" >  
                        <b>
                            <h:outputText value="Danh sách khách hàng"/>
                        </b>
                        <br/>

                        <p:scrollPanel> 
                            <p:dataList id="mdnTable" value="#{tblRawMoBean.mdnList}" var="item">
                                #{item}
                            </p:dataList>
                        </p:scrollPanel>

                        <p:commandButton value="Đóng" onclick="mdnDialog.hide()" type="button" />   

                    </p:dialog> 
                </h:form>
            </ui:define>

        </ui:composition>

    </body>
</html>
